package net.fdukedom.epicurus.presentation.actions.install;

import net.fdukedom.epicurus.presentation.actions.AbstractForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import javax.servlet.http.HttpServletRequest;

/**
 * Bean for install form.
 *
 * @author Dmitry Y. Kochelaev
 */
public class InstallForm extends AbstractForm {

    /**
     * Login of root user.
     */
    private String rootLogin;

    /**
     * Email of root user.
     */
    private String rootEmail;

    /**
     * Passwod of root user.
     */
    private String rootPassword;

    public ActionErrors doValidate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (rootLogin.length() == 0) {
            errors.add("error.install.login", new ActionMessage("install.errors.emptyLogin"));
        }
        if (rootPassword.length() == 0) {
            errors.add("error.install.password", new ActionMessage("install.errors.shortPassword"));
        }
        return errors;
    }

    public void doReset(ActionMapping mapping, HttpServletRequest request) {
        rootLogin = "root";
        rootEmail = "";
        rootPassword = "";
    }

    /**
     * Returns root login.
     *
     * @return root login
     */
    public String getRootLogin() {
        return rootLogin;
    }

    /**
     * Sets root login.
     *
     * @param rootLogin new login
     */
    public void setRootLogin(String rootLogin) {
        this.rootLogin = rootLogin;
    }

    /**
     * Returns root email.
     *
     * @return root email
     */
    public String getRootEmail() {
        return rootEmail;
    }

    /**
     * Sets root email.
     *
     * @param rootEmail new email
     */
    public void setRootEmail(String rootEmail) {
        this.rootEmail = rootEmail;
    }

    /**
     * Returns root password.
     *
     * @return root password
     */
    public String getRootPassword() {
        return rootPassword;
    }

    /**
     * Sets root password.
     *
     * @param rootPassword new password
     */
    public void setRootPassword(String rootPassword) {
        this.rootPassword = rootPassword;
    }
}
